package ar.camera.renderer.extend;


import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;

import android.content.Context;
import android.opengl.GLU;
import ar.camera.globject.Plane;
import ar.camera.pojo.GLPoint;
import ar.camera.renderer.base.BaseRenderer;

public class PlaneRenderer extends BaseRenderer {

	private Plane mPlane;

	public PlaneRenderer(Context mContext, GLPoint eye, GLPoint cam) {

		super(mContext, eye, cam);
		mPlane = new Plane();
	}

	@Override
	public void onDrawFrame(GL10 gl) {
		super.onDrawFrame(gl);

		GLU.gluLookAt(gl, eye.x, eye.y, eye.z, cam.x, cam.y, cam.z, 0f, 1f, 0f);

		gl.glMatrixMode(GL10.GL_PROJECTION);
		gl.glLoadIdentity();
		gl.glFrustumf(-ratio / 3, ratio / 3, (float) -1 / 3, (float) 1 / 3, 1f,
				1000f);

		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

		mPlane.draw(gl);
	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {
		super.onSurfaceChanged(gl, width, height);
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {

		gl.glDisable(GL11.GL_DITHER);
		gl.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_FASTEST);

		gl.glEnable(GL11.GL_CULL_FACE);
		gl.glShadeModel(GL11.GL_SMOOTH);
		gl.glEnable(GL11.GL_DEPTH_TEST);
	}
}
